package cn.xfdzx.android.apps.shop.presenter;

import java.util.List;
import java.util.Map;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.AfterServiceUpLoadMoreImgBean;
import cn.xfdzx.android.apps.shop.bean.AfterServiceUpLoadSingImgBean;
import cn.xfdzx.android.apps.shop.bean.MyFocusShopBean;
import cn.xfdzx.android.apps.shop.bean.OrderDetailInfoBeen;
import cn.xfdzx.android.apps.shop.bean.OrderProcessBeen;
import cn.xfdzx.android.apps.shop.bean.ReturnReasonBean;
import cn.xfdzx.android.apps.shop.bean.StoreInfoBeen;
import cn.xfdzx.android.apps.shop.contract.AfterServiceContract;
import cn.xfdzx.android.apps.shop.contract.MyFocusShopContract;
import cn.xfdzx.android.apps.shop.model.AfterServiceModel;
import cn.xfdzx.android.apps.shop.model.MyFocusShopModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;
import okhttp3.MultipartBody;

/**
 * @author zf
 * @date 2020/7/20.
 * Description：关注店铺
 */
public class MyFocusShopPresenter extends BasePresenter<MyFocusShopContract.View> implements MyFocusShopContract.Presenter {

    private MyFocusShopContract.Model model;

    public MyFocusShopPresenter() {
        model = new MyFocusShopModel();
    }

    @Override
    public void getCancleFocus(String storeid) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getCancleFocus(storeid)
                .compose(RxScheduler.<StoreInfoBeen>Flo_io_main())
                .as(mView.<StoreInfoBeen>bindAutoDispose())
                .subscribe(new Consumer<StoreInfoBeen>() {
                    @Override
                    public void accept(StoreInfoBeen bean) throws Exception {
                        mView.getCancleFocusSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });

    }

    @Override
    public void getFocusList(boolean isRefresh, boolean isLoading,String limit, int page) {
//View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        if (isLoading){
            mView.showLoading();
        }
        model.getFocusList(limit,page)
                .compose(RxScheduler.<MyFocusShopBean>Flo_io_main())
                .as(mView.<MyFocusShopBean>bindAutoDispose())
                .subscribe(new Consumer<MyFocusShopBean>() {
                    @Override
                    public void accept(MyFocusShopBean bean) throws Exception {
                        mView.getFocusListSuccess(bean);
                        if (isLoading){
                            mView.hideLoading();
                        }
                        if (isRefresh){
                            mView.finishRefresh();
                        }else {
                            mView.finishLoadMore();
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        if (isLoading){
                            mView.hideLoading();
                        }
                        if (isRefresh){
                            mView.finishRefresh();
                        }else {
                            mView.finishLoadMore();
                        }
                    }
                });

    }
}
